package com.bdqn.desiremall.command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bdqn.desiremall.entity.Mall_Favorites;
import com.bdqn.desiremall.serivce.favorites.FavoritesSerivce;
import com.bdqn.desiremall.serivce.favorites.FavoritesSerivceImpl;
import com.mvc.command.ICommand;

public class FavoritesCommand implements ICommand{
	Mall_Favorites favorites=new Mall_Favorites();
	FavoritesSerivce favoritesSerivce=new FavoritesSerivceImpl();
	/**
	 * 添加到收藏夹
	 * @param request
	 * @param response
	 */
	public void addFavorites(HttpServletRequest request,HttpServletResponse response){
		favorites.setFavoritesId(6);
		favorites.setUserId(2);
		favorites.setGoodsId(2);
		if(favoritesSerivce.favoritesofGoods(favorites))
		{
			try {
				request.getRequestDispatcher("BuyCar.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	/**
	 * 查询用户的收藏夹
	 * @param request
	 * @param response
	 */
	public void listFavorites(HttpServletRequest request,HttpServletResponse response){
		request.getSession().setAttribute("favoritesList",favoritesSerivce.favoritesCartView(1));
		try {
			request.getRequestDispatcher("Member_Collect.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void remove(HttpServletRequest request,HttpServletResponse response){
		if(favoritesSerivce.goodsRemoveFromfavorites(6))
		{
			try {
				request.getRequestDispatcher("Member_Collect.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
